﻿<cfscript>

/** 
* System Security Frameworks
* 
* @displayname "public.service.util.securityAdvice" 
* @hint "System Security Frameworks" 
* 
* @Output false
*/ 

component {
	
	/**
	* @hint "初始化对象"
	* 
	* @Output false
	*/
	public public.service.util.securityAdvice function init() {
		return this;
	}
	
	/**
	* @hint "判断当前访问是否使用AJAX技术"
	* 
	* @Output false
	*/
	public boolean function isAjaxRequest() {
		
		var httpHeaders = getHttpRequestData().headers;
		
		return (structKeyExists(httpHeaders, "X-Requested-With") and (httpHeaders["X-Requested-With"] eq "XMLHttpRequest"));
	}
	
	/**
	* @hint "判断当前访问是否启用HTTPS加密协议"
	* 
	* @Output false
	*/
	public boolean function isSecure() {		
	
		//通过ZXTM转发的安全连接信息有 WL-Proxy-SSL HTTP头标识
		//WL-Proxy-SSL
		var httpHeaders = getHttpRequestData().headers;
		
		//通过Apache转发的证书信息 可直接使用 isSecure 查看
		if (getPageContext().getRequest().isSecure()) {
			return true;
		}
		if (structKeyExists(httpHeaders, "WL-Proxy-SSL") and (httpHeaders["WL-Proxy-SSL"] eq "true")) {
			return true;
		}
		
		return false;
	}

	/**
	* @hint "返回远程用户的IP地址"
	* 
	* @Output false
	*/
	public string function getIP() {

		//WL-Proxy-Client-IP
		//X-Cluster-Client-Ip
		
		var _ip = CGI.REMOTE_ADDR;
		var _ip_proxy = getPageContext().getRequest().getHeader("X-Cluster-Client-Ip");
		var _ip_weblogic = getPageContext().getRequest().getHeader("WL-Proxy-Client-IP");

		if (isDefined("_ip_weblogic")) {
			_ip = _ip_weblogic;
		}
		if (isDefined("_ip_proxy")) {
			_ip = _ip_proxy;
		}
		
		return _ip;
	}

}
</cfscript>